package chinatelecom.feilong.framework.web.sys.dao;


import chinatelecom.feilong.framework.common.jpa.JpaRepository;
import chinatelecom.feilong.framework.web.sys.entity.Dictionary;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created by hnayan on 2017/9/4.
 */
public interface IDictinaryDao extends JpaRepository<Dictionary, Integer> {
    //通过code查找实体
    @Query("from Dictionary t where t.code = ?1 and t.isDelete = 0")
    Dictionary findByCode(String code);

    /**
     * 通过pId查找子数据列表
     * @param pId
     * @return
     */
    @Query(value = "select  * from sys_dictionary t where t.pId = ?1 and t.is_delete = 0",nativeQuery = true)
    List<Dictionary> findDictionaryListByPId(Integer pId);

    /**
     * 根据父ID和code来查询一个字段对象
     * @param pId
     * @param code
     * @return
     */
    @Query(value = "select  * from sys_dictionary t where t.pId = ?1 and t.code=?2 and t.is_delete = 0",nativeQuery = true)
    Dictionary findOneDictionaryByPIdAndCode(Integer pId,String code);

}
